<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isDeleteShow">
        <span class="text-wrap" @click="$emit('update:deleteAll',[])">全部删除</span>
        <span @click="isDeleteShow=!isDeleteShow">完成</span>
      </template>
      <van-icon v-else name="delete" @click="isDeleteShow=!isDeleteShow"/>
    </van-cell>
    <van-cell v-for="(item,index) in searchHistories" :key="index" :title="item"  @click="historyClick(item,index)">
      <van-icon v-show="isDeleteShow" name="close"/>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    historyClick (item, index) {
      if (this.isDeleteShow) {
        this.$emit('clear', index)
      } else {
        this.$emit('showRes', item)
      }
    }
  }
}
</script>

<style scoped lang="less">
  .search-history{
    .text-wrap{
      margin-right: 20px;
    }
  }
</style>
